//
//  ShowQRcodeView.m
//  AILock
//
//  Created by 谭亚明 on 2020/6/28.
//  Copyright © 2020 tym. All rights reserved.
//

#import "InputPasswordView.h"
#import "SGQRCodeObtain.h"
#import "UIView+ZFFrame.h"
#import "NSString+Option.h"
#import "Sizes.h"
#import "UIButton+Gradient.h"
#import "UserTool.h"
#import "UserModel.h"
#import "XMPayCodeView.h"

@interface InputPasswordView()

@property(nonatomic,weak) IBOutlet UIView *conView;

@end

@implementation InputPasswordView

-(void)awakeFromNib{
    [super awakeFromNib];
    self.conView.zf_width = ScreenWidth;
    self.backgroundColor = [[UIColor blackColor] colorWithAlphaComponent:0.5];
    [self.conView showTopCircularDead];
    
    
    XMPayCodeView *payView = [[XMPayCodeView alloc]initWithFrame:CGRectMake(0, 110, self.bounds.size.width, 60)];
    payView.secureTextEntry = YES;
    payView.backgroundColor = [UIColor whiteColor];
    payView.keywordHeightBlcok = ^(int height) {
        self.conView.frame = CGRectMake(0, ScreenHeight - height-200, ScreenWidth, 200);
    };
    
    [payView setPayBlock:^(NSString *payCode) {
        if (payCode.length == 6) {
            [self removeFromSuperview];
            
            if (self.showInputPasswordBlock) {
                self.showInputPasswordBlock(payCode);
            }
        }
    }];
    [self.conView addSubview:payView];
    self.codeView = payView;
}

-(IBAction)cancelAction:(id)sender{
    [self removeFromSuperview];
}


-(void)dealloc{
    NSLog(@"提示框释放");
}

+(void)showInputPasswordViewcompletion:(void(^)(NSString *passwordStr))completion{
    
    InputPasswordView *view = [[[NSBundle mainBundle] loadNibNamed:@"InputPasswordView" owner:self options:nil] lastObject];
    UIWindow *keyWindow = [[[UIApplication sharedApplication] windows] firstObject];
    view.showInputPasswordBlock = completion;
    view.frame = keyWindow.bounds;
    for (UIView *view in  keyWindow.subviews) {
        if ([view isKindOfClass:[InputPasswordView class]]) {
            [view removeFromSuperview];
        }
    }
    [keyWindow addSubview:view];
}



/*
 // Only override drawRect: if you perform custom drawing.
 // An empty implementation adversely affects performance during animation.
 - (void)drawRect:(CGRect)rect {
 // Drawing code
 }
 */

@end
